import { ConfigureService } from '@app/configure';
import { Injectable } from '@nestjs/common';

import Iot20180120 from '@alicloud/iot20180120';
import * as $OpenApi from '@alicloud/openapi-client';

@Injectable()
export class AlicloudService {
    constructor(
        private readonly config:ConfigureService
    ){}

    createIotClient() {
        const ali = this.config.get('alicloud')

        let config = new $OpenApi.Config({
            // 必填，您的 AccessKey ID
            accessKeyId: ali.accessKeyId,
            // 必填，您的 AccessKey Secret
            accessKeySecret: ali.accessKeySecret,
          });
          // Endpoint 请参考 https://api.aliyun.com/product/Iot
          config.endpoint = `iot.cn-shanghai.aliyuncs.com`;
          return new Iot20180120(config);
    }
}
